using System;
using SalesAndStoreApp.DAL.DAO;

namespace SalesAndStoreApp.DAL.Gateway
{
    public class ProductInventoryGateway:DbGateway
    {
        private ProductGateway productGateway = new ProductGateway();
        private InventoryGateway inventoryGateway = new InventoryGateway();

        public string SaveProductSetup(Product product)
        {
            try
            {
                Connection.Open();
                using (var transaction = Connection.BeginTransaction())
                {
                    Command.Transaction = transaction;
                    productGateway.SaveOrUpdate(ref product);
                    inventoryGateway.InsertOrUpdate(product);
                    transaction.Commit();
                    return "Product Setup done successfully!";
                }

            }
            catch (Exception exception)
            {
                Command.Transaction.Rollback();
                throw exception;
            }
            finally
            {
                CloseConnection(Connection);
            }
            
        }

        
    }
}